
 
 F u n c t i o n :   i n s e r t W i t h i n ( d o m I n s e r t i o n E l e m e n t ,   d o m E l e m e n t O r M a r k u p S t r i n g O r C S S S e l e c t o r ,   f u n c t i o n C a l l b a c k ( d o m E l e m e n t ) ) 
 
 
 
 D e s c r i p t i o n :   I n s e r t s   a   t a r g e t   D O M   e l e m e n t   w i t h i n   a n   e l e m e n t ,   m a r k u p   s t r i n g ,   o r   C S S   s e l e c t o r   r e f e r e n c e d   e l e m e n t   i n   t h e   D O M . 
 
 
 
 R e t u r n s :   d o m E l e m e n t ,   o r   $ A   o b j e c t   i f   c h a i n e d . 
 
 
 
 N o t e :   B e f o r e   t h e   n e w   c o n t e n t   i s   i n s e r t e d   i n t o   t h e   t a r g e t   D O M   e l e m e n t ,   a l l   p r e e x i s t i n g   c o n t e n t   w i l l   b e   c l e a n e d   a n d   r e m o v e d   t o   p r e v e n t   m e m o r y   l e a k s .   T h e   i n s e r t W i t h i n ( )   f u n c t i o n   i s   t h e   l i t e r a l   o p p o s i t e   o f   i n s e r t ( ) . 
 
 
 
 E x a m p l e : 
 
 
 
 / /   I n s e r t   a   D O M   e l e m e n t   w i t h i n   a n o t h e r   e l e m e n t   t a r g e t t e d   w i t h   a   C S S   s e l e c t o r 
 
 v a r   m y E l e m e n t   =   $ A . i n s e r t W i t h i n ( " # m y T a r g e t N o d e I d " ,   d o m E l e m e n t ) ; 
 
 
 
 / /   I n s e r t   a   m a r k u p   s t r i n g   e l e m e n t   w i t h i n   a n o t h e r   D O M   e l e m e n t 
 
 v a r   m y E l e m e n t   =   $ A . i n s e r t W i t h i n ( d o m E l e m e n t ,   ' < d i v > H e r e   w e   a r e   n o w ,   e n t e r t a i n   u s . < / d i v > ' ) ; 
 
 
 
 / /   I n s e r t   o n e   e l e m e n t   r e f e r e n c e d   b y   a   C S S   s e l e c t o r   w i t h i n   a n o t h e r   D O M   e l e m e n t 
 
 v a r   m y E l e m e n t   =   $ A . i n s e r t W i t h i n ( d o m E l e m e n t ,   " # m y T a r g e t N o d e T o M o v e " ) ; 
 
 
 
 / /   I n s e r t   a   D O M   e l e m e n t   w i t h i n   a n o t h e r   D O M   e l e m e n t   a n d   e x i c u t e   a   c a l l b a c k   w h e n   d o n e 
 
 v a r   m y E l e m e n t   =   $ A . i n s e r t W i t h i n ( d o m E l e m e n t T o T a r g e t ,   d o m E l e m e n t T o M o v e ,   f u n c t i o n ( d o m E l e m e n t T o M o v e )   { 
 
     / /   D o   s o m e t h i n g   w i t h   d o m E l e m e n t T o M o v e   a f t e r   t h e   i n s e r t i o n   i s   c o m p l e t e . 
 
 } ) ; 
 
 
 
 / /   O r   t h e   s a m e   u s i n g   c h a i n i n g 
 
 
 
 / /   I n s e r t   a   D O M   e l e m e n t   w i t h i n   a n o t h e r   e l e m e n t   t a r g e t t e d   w i t h   a   C S S   s e l e c t o r 
 
 v a r   m y C h a i n   =   $ A ( d o m E l e m e n t ) . i n s e r t W i t h i n ( " # m y T a r g e t N o d e I d " ) ; 
 
 
 
 / /   I n s e r t   a   m a r k u p   s t r i n g   e l e m e n t   w i t h i n   a n o t h e r   D O M   e l e m e n t 
 
 v a r   m y C h a i n   =   $ A ( ' < d i v > H e r e   w e   a r e   n o w ,   e n t e r t a i n   u s . < / d i v > ' ) . i n s e r t W i t h i n ( d o m E l e m e n t ) ; 
 
 
 
 / /   I n s e r t   o n e   e l e m e n t   r e f e r e n c e d   b y   a   C S S   s e l e c t o r   w i t h i n   a n o t h e r   D O M   e l e m e n t 
 
 v a r   m y C h a i n   =   $ A ( " # m y T a r g e t N o d e T o M o v e " ) . i n s e r t W i t h i n ( d o m E l e m e n t ) ; 
 
 
 
 / /   I n s e r t   a   D O M   e l e m e n t   w i t h i n   a n o t h e r   D O M   e l e m e n t   a n d   e x i c u t e   a   c a l l b a c k   w h e n   d o n e 
 
 v a r   m y C h a i n   =   $ A ( d o m E l e m e n t T o M o v e ) . i n s e r t W i t h i n ( d o m E l e m e n t T o T a r g e t ,   f u n c t i o n ( d o m E l e m e n t T o M o v e )   { 
 
     / /   D o   s o m e t h i n g   w i t h   d o m E l e m e n t T o M o v e   a f t e r   t h e   i n s e r t i o n   i s   c o m p l e t e . 
 
 } ) ; 
 
 
 
 / /   T o   r e t u r n   t h e   m o d i f i e d   e l e m e n t   w i t h i n   a   c h a i n ,   u s e   t h e   " r e t u r n ( ) "   m e t h o d . 
 
 
 
 v a r   m y E l e m e n t   =   m y C h a i n . r e t u r n ( ) ; 
 
 